package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.adapters.WeiQuanAdapter;
import com.lc.afbx.conn.GetApiWeiQuanZiXun;
import com.lc.afbx.widget.MyListView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/19.
 */
public class ConsultationActivity extends BaseActivity implements View.OnClickListener {


    private ListView consultation_lv;

    private List<GetApiWeiQuanZiXun.Data> dataList = new ArrayList<>();
    private WeiQuanAdapter adapter;

    private GetApiWeiQuanZiXun getApiWeiQuanZiXun = new GetApiWeiQuanZiXun(new AsyCallBack<GetApiWeiQuanZiXun.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiWeiQuanZiXun.Info info) throws Exception {

            dataList.addAll(info.dataList);

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(context, toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consultation);

        consultation_lv = ((ListView) findViewById(R.id.consultation_lv));

        consultation_lv.setDivider(null);

        consultation_lv.setAdapter(adapter = new WeiQuanAdapter(context, dataList));

        getApiWeiQuanZiXun.execute(this);

    }



    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.consultation_bt:

                if (BaseApplication.BasePreferences.readIsLogin()) {

                    startActivity(new Intent(this, ConsultationWantActivity.class));

                } else {

                    startActivity(new Intent(this, LoginActivity.class));

                }

                break;

            case R.id.consultation_title_right_rl:

                if (BaseApplication.BasePreferences.readIsLogin()) {

                    startActivity(new Intent(this, ConsultationMineActivity.class));

                } else {

                    startActivity(new Intent(this, LoginActivity.class));
                }

                break;

        }


    }


}
